package org.redis.cluster.command.info;

import java.util.LinkedHashMap;
import java.util.Map;

import org.redis.cluster.statistics.ConnectionStatistics;
import org.redis.cluster.statistics.TransportStatistics;

public class ClientsInfoFieldProvider implements InfoFieldProvider {
	
	private final static String GROUP="clients";

	@Override
	public String getGroup() {
		return GROUP;
	}

	@Override
	public Map<String, Object> getFields() {
		Map<String,Object> fields=new LinkedHashMap<String,Object>();
		fields.put("connected_clients", getConnectedClients());
		fields.put("client_longest_output_list", getClientLongestOutputList());
		fields.put("client_longest_input_buf", getClientLongestInputBuf());
		fields.put("client_longest_output_list_in_seconds", getClientLongestOutputListInSecond());
		fields.put("client_longest_input_buf_in_seconds", getClientLongestInputBufInSecond());
		return fields;
	}
	
	protected int getConnectedClients() {
		return ConnectionStatistics.getCurrentConnectCount();
	}
	
	protected int getClientLongestOutputList() {
		return TransportStatistics.getMaxOutput();
	}
	
	protected int getClientLongestInputBuf() {
		return TransportStatistics.getMaxInput();
	}
	
	protected int getClientLongestOutputListInSecond() {
		return TransportStatistics.getOutputInSecond();
	}
	
	protected int getClientLongestInputBufInSecond() {
		return TransportStatistics.getInputInSecond();
	}

}